<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"
	import="com.telecom.tree.*,java.util.*,com.telecom.cms.dao.*,java.sql.*,com.telecom.cms.dbconnect.*,com.telecom.cms.dto.*"%>
<%@ taglib uri="/WEB-INF/tree.tld" prefix="tree"%>

<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<title>客户群结果</title>
		<STYLE type=text/css></STYLE>
		<script type="text/javascript" src="js/dtree.js"></script>
		<script type="text/javascript" src="js/default.js"></script>
		<link rel="stylesheet" type="text/css" href="images/main.css">
		<%
			//String sql = (String) request.getSession().getAttribute("SQL");
			String countnumber = null;
			String latnid = null;
			if (null != request.getParameter("RSCOUNTNUM"))
				countnumber = String
				.valueOf(request.getParameter("RSCOUNTNUM"));
			if (null != request.getParameter("latn_id"))
				latnid = String.valueOf(request.getParameter("latn_id"));
		%>
		<SCRIPT>
<!--
	var checkedbox=null;
	function trim(str){  //删除左右两端的空格
 		return str.replace(/(^\s*)|(\s*$)/g, "");
	}
	
	function bconfirm(){
	        var Clustername = document.getElementById("Clustername").value;
			var box= document.getElementsByName("oldCluster");

			for(var i=0;i<box.length;i++){
				if(box[i].checked){
					var parfolderid=box[i].value;
				}
			}
			if(parfolderid==null&&Clustername==""){
                alert("请输入新客户群名称或选择一个已有的客户群!");
	  			return null;
			}

			//alert("saveClu.do?latn_id="+latnid+"&Clustername="+Clustername+"&cust_clu_id="+parfolderid+"&rcNbr="+<%=countnumber%>);
			document.getElementById("waitdiv").style.display="block";
			document.form1.action="saveClu.do?cust_clu_id="+parfolderid;
			document.form1.submit();			
			//window.location="saveClu.do?latn_id=<%=latnid%>&cust_clu_id="+parfolderid+"&rcNbr=<%=countnumber%>&Clustername="+Clustername;
	}
	
	function bgenfct(){
			var box= document.getElementsByName("oldCluster");

			for(var i=0;i<box.length;i++){
				if(box[i].checked){
					var parfolderid=box[i].value;
				}
			}
			if(parfolderid==null){
                alert("请选择一个客户群!");
	  			return null;
			}

	        window.location="cluster/waitstatus.jsp?latn_id=<%=latnid%>&cust_clu_id="+parfolderid;
	}
	
    function bcancel(){
        window.close();
    }
    function checksig(){
        var e = window.event.srcElement; 
        var estatus=e.checked;
        var y = document.getElementsByName("oldCluster"); 
        for(i=0;i<y.length;i++)
           y[i].checked=false;
		e.checked=estatus;
		if (estatus==true)
		   document.getElementById("Clustername").value="";
	}
	function checkno(){
        var y = document.getElementsByName("oldCluster"); 
        for(i=0;i<y.length;i++)
           y[i].checked=false;
	}
	function showhiddendiv(id){
		var divstyle=document.getElementById(id).style.display;
		if(divstyle=="none"){
			document.getElementById(id).style.display="";
			document.getElementById("img"+ id).src="images/minu_ico.gif";
		}else{
			document.getElementById(id).style.display="none";
			document.getElementById("img"+ id).src="images/plus_ico.gif";
		}

		
	}
      -->
    </SCRIPT>
	</head>
	<body>
		<div id="waitdiv" style="display:none">
			<iframe name="waiting" src="cluster/waitani.htm" frameborder="0" width="100%"
				height="150">
			</iframe>
		</div>
		<div id="addnode">
			<form name="form1" method="post" action="SaveCluAction.do">
				<table border="1" align="center" cellpadding="0" cellspacing="0">
					<tr>
						<td width="430" bgcolor="#f7f7f7">
							<FONT face="Arial, Helvetica, sans-serif"> <%
 	if (null == countnumber || countnumber.equals(""))
 		//out.print("<b>已有的分群结果</b><br>选择一个客户群，然后只需等几分钟，您就可以看到这个群内用户的详细评估信息了。");
 		out.print("<br>客户群已生成，我们会持续提供对客户群的分析和评估功能。");
 	else
 		out.print("<b>保存分群结果</b><br>下一步操作之前，需要将满足条件的用户号码存下。您需要输入一个有意义的名称如‘泰山计划2007-7-23’，当然，您也可以选择覆盖以前的结果。");
 %> <br> <br> </FONT>
						</td>
					</tr>
					<%
					if (null != countnumber && !countnumber.equals("")) {
					%>
					<tr>
						<td width="430" bgcolor="#f7f7f7">
							<FONT face="Arial, Helvetica, sans-serif"><b> 存为新客户群:
							</B> </FONT>
						</td>
					</tr>
					<tr>
						<td>
							<INPUT name="Clustername" type="text" onClick="checkno()"
								id="Clustername" size=35>
						</td>
					</tr>
					<%
					}//end of if
					%>
					<tr>
						<td bgcolor="#f7f7f7">
							<%
								if (null == countnumber || countnumber.equals(""))
									out.print("<b>选择一个用户群：</b>");
								else
									out.print("<b>覆盖以下用户群:</b>");
							%>
							<FONT face="Arial, Helvetica, sans-serif"> </font>
						</td>
					</tr>
					<%
									int APP_SUBJECT_ID = ((Integer) session
									.getAttribute("APP_SUBJECT_ID")).intValue();
							Connection con = GetConnect.getCsConnection();
							CustCluDAO custcludao = new CustCluDAO();
							List custclulist = null;
							if (null != countnumber && !countnumber.equals("")) {
								custclulist = custcludao.findAll(latnid, APP_SUBJECT_ID);
					%>
					<tr>
						<td height="29" align="left" valign="top" bgcolor="#f0f0ff"
							style="PADDING-TOP: 3px">
							<input type="hidden" name="latn_id" value="<%=latnid %>">
							<input type="hidden" name="rcNbr" value="<%=countnumber%>">
							<%
							for (int i = 0; i < custclulist.size(); i++) {
							%>
							<input type="checkbox" name="oldCluster" onClick="checksig()"
								value="<%=((CustClu) custclulist.get(i)).getCustCluId()%>">
							<%=((CustClu) custclulist.get(i)).getCustCluName()%>
							(上次结果保存时间:
							<%=((CustClu) custclulist.get(i)).getCreateTime()%>
							用户数:
							<%=((CustClu) custclulist.get(i)).getPrdNbr()%>
							)
							<br>
							<%
							}//end of for
							%>

						</td>
					</tr>
					<%
							} else {
							SEG_APP_SUBJECT_DEFDAO app = new SEG_APP_SUBJECT_DEFDAO(con);
							List applist = app.findAll();
							Iterator it = applist.iterator();
							while (it.hasNext()) {
								SEG_APP_SUBJECT_DEFDTO dto = (SEG_APP_SUBJECT_DEFDTO) it
								.next();
								String appName = dto.getAPP_SUBJECT_NAME();
								int appId = dto.getAPP_SUBJECT_ID();

								custclulist = custcludao.findAll(latnid, appId);
					%>
					<tr>
						<td onclick="showhiddendiv('<%=appId %>')" style="cursor:hand">
							<img id="img<%=appId %>" src="images/plus_ico.gif" width="10" height="10"><%=appName%>
						</td>
					</tr>
					<tr>
						<td id=<%=appId%> height="29" align="left" valign="top" bgcolor="#f0f0ff"
							style="PADDING-TOP: 3px; display:none">
							<input type="hidden" name="latn_id" value="<%=latnid %>">
							<input type="hidden" name="rcNbr" value="<%=countnumber%>">
							<%
							for (int i = 0; i < custclulist.size(); i++) {
							%>
							<input type="checkbox" name="oldCluster" onClick="checksig()"
								value="<%=((CustClu) custclulist.get(i))
												.getCustCluId()%>">
							<%=((CustClu) custclulist.get(i))
										.getCustCluName()%>
							(上次结果保存时间:
							<%=((CustClu) custclulist.get(i))
										.getCreateTime()%>
							用户数:
							<%=((CustClu) custclulist.get(i)).getPrdNbr()%>
							)
							<br>
							<%
							}//end of for
							%>

						</td>
					</tr>
					<%
							}
							custclulist = custcludao.findAll(latnid, 0);
					%>
					<tr>
						<td onclick="showhiddendiv('0')" style="cursor:hand">
							<img id="img0" src="images/plus_ico.gif">无主题
						</td>
					</tr>
					<tr>
						<td id=<%=0%> height="29" align="left" valign="top"
							bgcolor="#f0f0ff" style="PADDING-TOP: 3px; display:none">
							<input type="hidden" name="latn_id" value="<%=latnid %>">
							<input type="hidden" name="rcNbr" value="<%=countnumber%>">
							<%
							for (int i = 0; i < custclulist.size(); i++) {
							%>
							<input type="checkbox" name="oldCluster" onClick="checksig()"
								value="<%=((CustClu) custclulist.get(i)).getCustCluId()%>">
							<%=((CustClu) custclulist.get(i)).getCustCluName()%>
							(上次结果保存时间:
							<%=((CustClu) custclulist.get(i)).getCreateTime()%>
							用户数:
							<%=((CustClu) custclulist.get(i)).getPrdNbr()%>
							)
							<br>
							<%
							}//end of for
							%>
						</td>
					</tr>
					<%
					}
					%>
					<tr>
						<td valign="middle" align="center" bgcolor="#f7f7f7">
							<%
							if (null != countnumber && !countnumber.equals("")) {
							%>
							<input type=button name=inputboxbt value=保存 onClick="bconfirm();">
							<INPUT type=button name=inputboxbs value=关闭 onClick="bcancel();">
							<%
							} else {
							%>
							<!--input type=button name=inputboxbt value=生成分析数据 onClick="bgenfct();"-->
							<input type=button name=inputboxbt value=关闭窗口 onClick="bcancel();">
							<%
							}
							%>
						
					</tr>
				</table>
			</form>
		</div>


		<br>
		<p align="center">
			<a href="cluster/waitstatus.jsp"></a>
	</body>
</html>
